# coding = utf-8
import random
from flask import Blueprint
from common import DateTimeUtil

inletPr = Blueprint("inletPressure", __name__)

class FluctuateValues():
    #0.2-0.3
    def FluctuateValues(self):
        value={
            "InletPressure": str(round(random.uniform(0.1,1),2)),       #进口压力0.1~1
            "OutletPressure": str(round(random.uniform(0.2,1),2)),      #出口压力0.2-2
            "BoosterPumpOutletPressure": str(random.randint(100,120)),  #增压泵出口压力100-120
            "HighCavityPressure": str(random.randint(100,120)),         #高压腔压力100-120
            "SuperhighCavityPressure": str(random.randint(100,120)),    #超高压腔压力100-120
            "Ua_Voltage": str(random.randint(370, 380)),                #A相电压370~380
            "Ub_Voltage": str(random.randint(370, 380)),                #B相电压370~380
            "Uc_Voltage": str(random.randint(370, 380)),                #C相电压370~380
            "Ia_Current": str(random.randint(3,5)),                     #A相电流3~5
            "Ib_Current": str(random.randint(3, 5)),                    #B相电流3~5
            "Ic_Current": str(random.randint(3, 5)),                    #C相电流3~5
            "InstantaneousFlow": str(FluctuateValues().InstantaneousFlowValue()),
            "Turbidity": str(round(random.uniform(0, 3), 1)),             # 浊度
            "Conductivity": str(round(random.uniform(1000, 1500), 0)),  # 电导率
            "DissolvedOxygen": str(round(random.uniform(5, 15), 0)),    # 溶解氧
            "ResidualChlorine": str(round(random.uniform(0, 0.3), 1)),  # 余氯
            "PH": str(round(random.uniform(6, 8.5), 1)),                # 酸碱度
            "WaterTemperature": str(round(random.uniform(20, 35), 0))   # 水温
        }
        return value


    '''
    瞬时流量1.9 - 2.1波动
    每天7~9、11~13、17：30~ 20三个时间段的流量3~3.5
    '''
    def InstantaneousFlowValue(self):
        currentDate=DateTimeUtil.get_current_date_HMS()
        if('07:00:00'<=currentDate<='09:59:59' or '11:00:00'<=currentDate<='13:59:59' or '17:30:00'<=currentDate<='20:59:59'):
            InstantaneousFlowValue=round(random.uniform(3.0,3.5),2)
            return InstantaneousFlowValue
        else:
            InstantaneousFlowValue = round(random.uniform(1.9, 2.1), 2)
            return InstantaneousFlowValue


    #提供外部接口调用，可以不写，忽略
    @staticmethod
    @inletPr.route('/InletPressureValue')
    def InletPressure():
        print("just a InletPressure")
        return "just a InletPressure"


# value = FluctuateValues().FluctuateValues()
# print(value)